﻿<?
	$DATABASE_HOST = 'localhost';
	$DATABASE_NAME = 'gambit';
	$DATABASE_USER = 'root';
	$DATABASE_PASS = 'root';
	
	$db = mysql_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS);
	mysql_query("set character set 'utf8'");//读库 
	mysql_query("set names 'utf8'");
	if(!$db)
	{
		echo '没有连接到数据库,请检查连接!';
		exit();	
	}
	mysql_select_db($DATABASE_NAME, $db);
	
	class ban
	{
		private $count = '100';
		private $table = 'gb_users';
		function gb_users()
		{
			@$page = intval($_GET['page']);
			$query = mysql_query("SELECT * FROM `$this->table`");
			$ranks = mysql_num_rows($query);
			$total = intval(($ranks - 1) / $this->count) + 1;
			if( empty( $page ) or $page < 0) $page = 1;
			if( $page > $total ) $page = $total;
			$start = $page * $this->count - $this->count;
			$sql = 'SELECT `gb_users`.`uName`, `gb_users`.`uLvl`, `gb_users`.`uMoney`, `gb_users`.`uBank` FROM `gb_users` ORDER BY `uMoney` + `uBank` DESC LIMIT '.$start.','.$this->count.'';
			$mysql = mysql_query($sql) or die("ERROR ".mysql_errno()." ".mysql_error()."<br /> 查询: ".$sql."");
			$r = mysql_fetch_array($mysql);
			$numb = intval($page * $this->count) - $this->count;
			do
			{
				$numb ++;
				$amount = $r['uMoney'] + $r['uBank'];
				echo '
					<tr class="table_cont" align="center">
                    	<td>'.$numb.'</td>
                        <td>'.$r['uName'].'</td>
						<td>'.$amount.'</td>
						<td>'.$r['uLvl'].'</td>
					</tr>
				';
			}
			while($r = mysql_fetch_array($mysql));
		}
		function page()
		{
			$sql = 'SELECT * FROM `'.$this->table.'`';
			$mysql = mysql_query($sql);
			$ranks = mysql_num_rows($mysql);
			$page = intval(($ranks - 1) / $this->count) + 1;
			for($i = 0; $i < $page; $i++)
			{
				echo '<div class="page_1"><a href="/mindex.php?page='.($i + 1).'">'.($i + 1).'</a></div>';
			}
		}
		function disconect()
		{
			mysql_close();	
		}
	}
?>